$(function() {
    $(".mobile").html(localStorage.userMobile);
    //获取手机验证码
    var token = localStorage.token;
    var flag = false;
    $(".code").on("click",function() {
        if(flag) return false;
        var mobile = localStorage.userMobile;
        $.ajax({
            type: "post",
            url: domain.test + "/gettelcode",
            data: {
                mobile:mobile
            },
            success: function (response) {
                console.log(response);
                if(response.data.rtnCode===200) {
                    var counter = 90;
                    var timer = setInterval(function() {
                        counter--;
                        if(counter===0) {
                            $(".code").html("获取短息验证码");
                            clearInterval(timer);
                        }else {
                            $(".code").html(counter + "s");
                            flag = true;
                        }
                    },1000);
                }
            }
        });
    });
    //修改登录密码
    function tips(tips) {
        $(".tips").css("display", "block").html(tips).animate({
            "opacity": 1
        }, 1000, function () {
            setTimeout(function () {
                $(".tips").animate({
                    "opacity": 0
                }, 1000, function () {
                    $(".tips").css("display", "none");
                })
            }, 1000);
        })
    }
    $(".submitBtn").on("click",function() {
        var userName = localStorage.userName;
        var mobile = localStorage.userMobile;
        var code = parseInt($(".codeNum").val());
        if(!code) {
            tips("请输入验证码");
            return false;
        }
        var psd = $(".newPsd").val();
        if(!psd) {
            tips("请输入新密码");
            return false;
        }
        if(psd.length<6||psd.length>20) {
            tips("密码长度为6-20位");
            return false;
        }
        $.ajax({
            type: "post",
            url: domain.test + "/resetpsd",
            data: {
                userName:userName,
                password:psd,
                mobile:mobile,
                captcha:1234,
                os:"iOS",
                pushId:"sir555"
            },
            success: function (response) {
                console.log(response);
                if(response.data.rtnCode===200) {
                    localStorage.token = "";
                    tips("修改成功，请重新登录！");
                    setTimeout(function() {
                        location.href = "../loginAndReg/login.html";
                    },1000);
                }
                if(response.data.rtnCode===400) {
                    tips(response.data.msg);
                }
            }
        });
    });
});